package de.koller.million.card.engine.player;

import de.koller.million.card.engine.item.Item;
import de.koller.million.card.engine.item.ItemSlot;
import de.koller.oceanFramework.OceanException;
import java.util.HashMap;
import java.util.Map;

public class Equipt {

	private final Player player;
	protected final Map<ItemSlot, Item> equipt = new HashMap<>();
	private long lastEquipt = 0;

	public Equipt( Player player ) {
		this.player = player;
	}
	
	public Item get( ItemSlot slot ) {
		return equipt.get( slot );
	}
	
	public Item equip( Item item ) {
		Item old = equipt.get( item.getSlot() );
		
		if( old == item )
			throw new OceanException( "already equipt" );
		
		equipt.put( item.getSlot(), item );
		player.stats.equiptChanged();
		lastEquipt = player.croot.getTime();
		return old;
	}
	
	public boolean isBetter( Item item ) {
		if( item == null )
			return false;
		
		Item e = get( item.getSlot() );
		if( e == null )
			return true;
		
		double equippedDamage = e.getDamage();
		double newDamage = item.getDamage();
		
		return newDamage > equippedDamage;
	}

	public long getLastEquipt() {
		return lastEquipt;
	}
	
}
